package com.tarena.lbs.activity.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tarena.lbs.activity.dao.mapper.ActivityMapper;
import com.tarena.lbs.activity.dao.repository.ActivityRepository;
import com.tarena.lbs.activity.pojo.po.ActivityPO;
import com.tarena.lbs.activity.pojo.query.ActivityQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class ActivityRepositoryImpl implements ActivityRepository {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public PageInfo<ActivityPO> pageListByBusinessId(ActivityQuery query) {
        QueryWrapper<ActivityPO> queryWrapper = new QueryWrapper<>();
        PageHelper.startPage(query.getPageNo(), query.getPageSize());
        queryWrapper
                .eq("business_id", query.getBusinessId())
                .eq("delivery_channel", query.getDeliveryChannel())
                .eq("activity_name", query.getActivityName())
                .eq("activity_type", query.getType())
                .eq("channel_type", query.getChannelType())
                .eq("status", query.getStatus());
        queryWrapper
                .gt("start_date", query.getStartDate())
                .lt("end_date", query.getEndDate());
        return new PageInfo<>(activityMapper.selectList(queryWrapper));
    }

    @Override
    public ActivityPO selectActivityById(Integer id) {
        return activityMapper.selectById(id);
    }

    @Override
    public void insert(ActivityPO po) {
        activityMapper.insert(po);
    }

    @Override
    public void updateById(ActivityPO po) {
        activityMapper.updateById(po);
    }
}
